package com.redis.springbootredis;

import com.redis.springbootredis.entity.People;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.*;

@SpringBootTest
class SpringbootRedisApplicationTests01 {

    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    //没重写前的对象写入
//    @Test
//    void test1() {
//        ValueOperations<Object, Object> opsForValue = redisTemplate.opsForValue();
//        People people = new People(1,"ljw");
//        opsForValue.set("1",people);
//        System.out.println(opsForValue.get("1"));
//    }

    //重写后的对象写入
    @Test
    void test2() {
        ValueOperations<String, Object> opsForValue = redisTemplate.opsForValue();
        People people = new People(2,"fzt");
        opsForValue.set("2",people);
        System.out.println(opsForValue.get("2"));
    }

    //String
    @Test
    void test3() {
        ValueOperations<String, Object> opsForValue = redisTemplate.opsForValue();
        opsForValue.set("stringone","test");
        System.out.println(opsForValue.get("stringone"));
    }

    //list
    @Test
    void test4() {
        ListOperations<String, Object> opsForList = redisTemplate.opsForList();
        opsForList.leftPush("redislist","hh");
        System.out.println(opsForList.index("redislist",1));
    }

    //hash
    @Test
    void test5() {
        HashOperations<String, Object, Object> opsForHash = redisTemplate.opsForHash();
        People people = new People(3,"ylc");
        opsForHash.put("redishash","001",people);
        System.out.println(opsForHash.get("redishash","001"));
    }

    //set
    @Test
    void test6() {
        SetOperations<String, Object> opsForSet = redisTemplate.opsForSet();
        opsForSet.add("redisset",new People(4,"abc"));
        System.out.println(opsForSet.members("redisset"));
    }

    //Zset
    @Test
    void test7() {
        ZSetOperations<String, Object> opsForZSet = redisTemplate.opsForZSet();
        opsForZSet.add("redisZset",new People(5,"fzt"),4);
        opsForZSet.add("redisZset",new People(6,"abc"),5);
        opsForZSet.add("redisZset",new People(7,"def"),6);
        System.out.println(opsForZSet.range("redisZset",0,-1    ));
    }

}
